Skip to content

Use consistent HTML escaping in error details fragment - #3466

Merged
akrabat merged 4 commits into
slimphp:4.xfrom
iliaal:fix/html-error-renderer-escape-consistency
Nov 15, 2026
Merged

akrabat merged 4 commits into
slimphp:4.xfrom
iliaal:fix/html-error-renderer-escape-consistency

Conversation

@iliaal

@iliaal iliaal commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

HtmlErrorRenderer::renderExceptionFragment() escapes the exception message and stack trace with bare htmlentities(), while the title and description are escaped with explicit htmlspecialchars(..., ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'). The two escape sites therefore behave differently across the supported PHP range: htmlentities() default flags gained ENT_QUOTES only in PHP 8.1, so on 7.4/8.0 single quotes in the message pass through unescaped, and the charset is inherited from the default_charset ini rather than pinned to UTF-8.

This aligns the fragment escaping with the same explicit call used everywhere else in the renderer, making behavior identical on every supported PHP version.

The exception message and trace in renderExceptionFragment() used bare
htmlentities(), whose default flags differ across PHP versions and
inherit the default_charset ini, while the title and description are
escaped with explicit ENT_QUOTES | ENT_SUBSTITUTE flags and a pinned
UTF-8 charset. Align the fragment escaping with the same explicit call
so behavior is identical on every supported PHP version.
@coveralls

coveralls commented Aug 23, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 99.454% (-0.001%) from 99.455% — iliaal:fix/html-error-renderer-escape-consistency into slimphp:4.x

iliaal and others added 2 commits August 23, 2026 16:08
File, Type, Code, and Line were interpolated into the details fragment
without escaping. File paths and anonymous class names can contain HTML
metacharacters, and Throwable::getCode() is untyped. Route every fragment
field through the same htmlspecialchars() flags as title and description.
@akrabat
akrabat merged commit 3620b97 into slimphp:4.x Nov 15, 2026
9 of 11 checks passed
@akrabat

akrabat commented Nov 15, 2026

Copy link
Copy Markdown
Member

Thanks @iliaal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants